package com.qin.entity;

import com.qin.entity.subcomponents.*;
import lombok.Data;

@Data
public class SubComponent {

    //主键
    private String subcomponent_id;
    //所属组件ID
    private String component_id;
    //序号
    private int order_number;
    //子组件名称
    private String sub_component_name;
    //子组件类型（0-正则变量提取,1-列名变量提取,2-变量校验,3-变量轮询,4-生成临时变量,5-生成随机数,6-生成日期）
    private int sub_component_type;
    //是否执行（0-否，1-是）
    private int is_used;

    //【正则变量提取】正则表达式
    private String regex_text;
    //【正则变量提取】赋值变量名
    private String regex_assign_paraname;

    //【列名变量提取】列名
    private String column_name;
    //【列名变量提取】赋值变量名
    private String column_assign_paraname;

    //【变量校验】临时变量名
    private String check_paraname;
    //【变量校验】预期值
    private String check_expect_value;

    //【变量轮询】临时变量名
    private String poll_paraname;
    //【变量轮询】提取列名
    private String poll_column_name;
    //【变量轮询】目标值
    private String poll_target_value;
    //【变量轮询】轮询间隔
    private int poll_interval;
    //【变量轮询】轮询时长
    private int poll_duaration;

    //【生成临时变量】变量名
    private String temp_paraname;
    //【生成临时变量】变量值
    private String temp_paravalue;

    //【生成随机数】变量名
    private String random_paraname;
    //【生成随机数】随机数类型
    private int random_type;
    //【生成随机数】位数
    private int random_digit;

    //【生成日期】变量名
    private String date_paraname;
    //【生成日期】日期
    private String date_date;
    //【生成日期】日期格式
    private String date_format;

    public void execute(ExecuteBean executeBean){

        //设置ExecuteBean对象的各属性
        executeBean.setSubcomponent_id(subcomponent_id);
        //执行当前子组件内容
        //0-正则变量提取
        if(this.getSub_component_type() == 0){
            RegexExtractSubbComponent regexExtractSubbComponent = new RegexExtractSubbComponent(component_id, regex_text, regex_assign_paraname);
            regexExtractSubbComponent.execute(executeBean);
        }
        //1-列名变量提取
        else if(this.getSub_component_type() == 1){
            ColumnExtractSubComponent columnExtractSubComponent = new ColumnExtractSubComponent(component_id, column_name, column_assign_paraname);
            columnExtractSubComponent.execute(executeBean);
        }
        //2-变量校验
        else if(this.getSub_component_type() == 2){
            CheckParaSubComponent checkParaSubComponent = new CheckParaSubComponent(check_paraname, check_expect_value);
            checkParaSubComponent.execute(executeBean);
        }
        //3-变量轮询
        else if(this.getSub_component_type() == 3){
            PollSubComponent pollSubComponent = new PollSubComponent(component_id, poll_paraname, poll_column_name, poll_target_value, poll_interval, poll_duaration);
            pollSubComponent.execute(executeBean);
        }
        //4-生成临时变量
        else if(this.getSub_component_type() == 4){
            TempParaSubComponent tempParaSubComponent = new TempParaSubComponent(temp_paraname, temp_paravalue);
            tempParaSubComponent.execute(executeBean);
        }
        //5-生成随机数
        else if(this.getSub_component_type() == 5){
            RandomParaSubComponent randomParaSubComponent = new RandomParaSubComponent(random_paraname, random_type, random_digit);
            randomParaSubComponent.execute(executeBean);
        }
        //6-生成日期
        else if(this.getSub_component_type() == 6){
            DateSubComponent dateSubComponent = new DateSubComponent(date_paraname, date_date, date_format);
            dateSubComponent.execute(executeBean);
        }

    }

}
